import baseService from "@/service/baseService";
import appService from "@/service/appService";
import { IObject } from "@/types/interface";

/** 全局业务相关 API */

// /** 系统列表 API */
// export const systemApi = {
//   // /** 系统分页查询 GET system/listview/page */
//   getPage: (params: IObject) => baseService.get("system/listview/page", params),
//   /** 获取系统状态 GET system/listview/systatus */
//   // getStatus: () => baseService.get("system/listview/systatus"),
//   getStatus: (params: IObject) => baseService.post("system/listview/systatus", params),
//   /** 获取系统统计数据 GET system/listview/statistics */
//   getStatistics: () => baseService.get("system/listview/statistics")
// };
/** APP 端：系统列表相关 API */
export const systemAppApi = {
  /** 获取系统列表 GET /installer/web/hemsList */
  getList: (params: IObject, headers?: IObject) =>
    appService.get("installer/web/hemsList", params, headers),
  /** 获取系统详情 POST /installer/web/detail */
  getDetail: (data: IObject, headers?: IObject) =>
    appService.post("installer/web/detail", data, headers),
  /** 获取设备列表 GET /hems/installer/deviceList */
  getDeviceList: (params: IObject, headers?: IObject) =>
    appService.get("hems/installer/deviceList", params, headers),
  /** 获取系统设置信息 GET /hems/system/submit */
  getSystemSettings: (params: IObject, headers?: IObject) =>
    appService.post("hems/system/submit", params, headers),
  // /** 获取能源系统统计数据 GET /installer/web/energy */
  getEnergyStats: (params: IObject, headers?: IObject) =>
    appService.get("installer/web/energy", params, headers)
};

/** APP 端：能源统计相关 API */
export const energyAppApi = {
  // 全部 - 光伏 电池 电网 家庭
  getSolarFlowAllList: (data: IObject, headers?: IObject) =>
    appService.post("/as/tdengine/hems/energy", data, headers),
  // SOC
  getSolarFlowHemsElectricList: (data: IObject, headers?: IObject) =>
    appService.post("/as/tdengine/hems/electric", data, headers),
  // 光伏
  getSolarFlowList: (params: IObject, headers?: IObject) =>
    appService.get("/as/tdengine/device/solarFlow/energy", params, headers),
  // 电网
  getCtHemsList: (data: IObject, headers?: IObject) =>
    appService.post("/as/tdengine/device/smartct/energy", data, headers),
  // ...
  // getCtHemsList: (data: IObject, headers?: IObject) =>
  //   appService.post("/as/tdengine/hems/cthems", data, headers),
  // ...
  postPvList: (data: IObject, headers?: IObject) =>
    appService.post("/as/tdengine/hems/pvlist", data, headers)
};
// 调用web端告警分页查询
export const alertAppApi = {
  getPage: (params: IObject, headers?: IObject) => baseService.get("alert/page", params, headers)
};

/** 告警管理 API */
export const alertApi = {
  /** 告警分页查询 GET alerts/page */
  getPage: (params: IObject, headers?: IObject) => baseService.get("alerts/page", params, headers),
  /** 告警导出 GET alerts/export */
  export: (params: IObject, headers?: IObject) => baseService.get("alerts/export", params, headers)
};

/** 个人账号（全局） API */
export const accountSelfApi = {
  /** 获取个人信息 GET /sys/user/info */
  getInfo: () => baseService.get("sys/user/info"),
  /** 修改密码 PUT /sys/user/password */
  updatePassword: (data: IObject) => baseService.put("sys/user/password", data),
  /** 修改用户名 PUT /sys/user/username */
  updateUsername: (data: IObject) => baseService.put("sys/user/username", data),
  /** 退出登录 POST /logout */
  logout: () => baseService.post("/logout")
};

/** 组织信息（全局业务） API */
export const organizationBizApi = {
  /** 组织详情 GET /sys/organization/{id} */
  getById: (id: string) => baseService.get(`sys/organization/${id}`),
  /** 组织信息修改 PUT /sys/organization */
  update: (data: IObject) => baseService.put("sys/organization", data)
};

// 获取系统概览
export function getSystemOverview(id: string) {
  return baseService.get(`/system/listview/hems/${id}`);
}

// 获取光伏能量统计
export function getSolarData() {
  return baseService.get("/system/listview/solar/data");
}

// 获取家用能量统计
export function getHomeData() {
  return baseService.get("/system/listview/home/data");
}

// 获取电池充电统计
export function getBatteryChargeData() {
  return baseService.get("/system/listview/battery/charge");
}

// 获取电池放电统计
export function getBatteryDischargeData() {
  return baseService.get("/system/listview/battery/discharge");
}

// 获取SOC统计
export function getSocData() {
  return baseService.get("/system/listview/battery/soc");
}

// 获取电网输出统计
export function getGridOutputData() {
  return baseService.get("/system/listview/grid/output");
}

// 获取电网输入统计
export function getGridInputData() {
  return baseService.get("/system/listview/grid/input");
}

// 设备分页
export function getDevicePage(params: any) {
  return baseService.get("/device/page", { params });
}

// 告警分页
export function getAlertPage(params: any) {
  return baseService.get("/alert/page", { params });
}

// 获取系统设置信息
export function getSystemSettings() {
  return baseService.get("/settings");
}
